import Prices from '~/components/prices.vue';
import Lab from '~/components/lab.vue'
import Setting from '~/components/setting.vue'
import { ITab } from '~/models';

const ComponentUtil = {
  eqal: (a: any, b: any) => {
    return a.title == b.title
  },
  find: (_list: any[], _item: any) => {
    for (let i = 0;i < _list.length; i++) {
      if (
        _list[i] != null &&
        ComponentUtil.eqal(_list[i], _item)
      ) {
        return i
      }
    }
    return -1
  }
}

const WatcherUtil = {
  eqal: (a: ITab, b: ITab) => {
    return a.swap.provider == b.swap.provider &&
    a.pair.address == b.pair.address
  },
  find: (_list: any[], _item: any) => {
    for (let i = 0; i < _list.length; i++) {
      if (
        _list[i] != null &&
        WatcherUtil.eqal(_list[i], _item)
      ) {
        return i
      }
    }
    return -1
  }
}

export const TabUtil = {
  eqal: (a: any, b: any) => {
    if (!a || !b) return false

    if (a.type == 'component' && b.type == 'component') {
      return ComponentUtil.eqal(a, b)
    }
    else if (a.type == 'monitor' && b.type == 'monitor') {
      return WatcherUtil.eqal(a, b)
    }
    else {
      return false
    }
  },
  find: (_list: any[], _item: any) => {
    for (let i = 0; i < _list.length; i++) {
      if (
        _list[i] != null &&
        _list[i].type == _item.type &&
        TabUtil.eqal(_list[i], _item)
      ) {
        return i
      }
    }
    return -1
  }
}

export const tabPrices = {
  type: 'component',
  title: 'Price List',
  component: Prices,
}

export const labSetting = {
  type: 'component',
  title: 'Lab',
  component: Lab,
}

export const tabSetting = {
  type: 'component',
  title: 'Setting',
  component: Setting,
}

export default TabUtil